﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Company.Hardware.Camera
{
    public abstract class CameraBase : ICamera
    {
        public CameraConfig CameraConfig { get; private set; }
        public bool Initialized {get;private set;}

        public event Action<Photo> OnGrabbed;

        public void Closed()
        {
            if (Initialized)
            {
                DoClose();
                Initialized = false;
            }
        }

        public bool Init(CameraConfig cameraConfig)
        {
            CameraConfig = cameraConfig;
            if (Initialized) 
            {
                throw new Exception("相机初始化完成");
            }

            if (DoInit())
            {
                if (Initialized)
                {
                    Initialized = true;
                    return true;

                }
                
            }
            return false;
        }

        protected void InvokeOnGrabbed(Photo image)
        {
            if (OnGrabbed==null) return;
            foreach (Action<Photo> item in OnGrabbed.GetInvocationList())
            {
                item.Invoke(image);
            }
        }

        public abstract bool Trigger();

        public abstract bool DoClose();
        public abstract bool DoInit();




    }
}
